/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Entity.Etbl_Package_tour_types;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author mrteo
 */
public class DALtbl_Package_tour_types extends BaseConnection {
    CallableStatement clbStm=null;
    ResultSet rs=null;
    
    public boolean addtbl_Package_tour_types(Etbl_Package_tour_types obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tour_types_add(?,?)}");           
            clbStm.setString("name",obj.getName());
            clbStm.setString("description",obj.getDescription());            
            clbStm.execute();
            clbStm.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tour_types.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public boolean edittbl_Package_tour_types(Etbl_Package_tour_types obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tour_types_update(?,?,?)}");
            clbStm.setInt("tourtype_Id",obj.getTourtype_Id());
            clbStm.setString("name",obj.getName());
            clbStm.setString("description",obj.getDescription());           
            clbStm.execute();
            rs.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tour_types.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public boolean deletetbl_Package_tour_types(int tourtype_Id){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tour_types_delete(?)}");
            clbStm.setInt("tourtype_Id",tourtype_Id);           
            clbStm.execute();
            clbStm.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tour_types.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public Etbl_Package_tour_types getOnetbl_Users(int tourtype_Id){
          Etbl_Package_tour_types obj=new Etbl_Package_tour_types();
          try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tour_types_get(?)}");
            clbStm.setInt("tourtype_Id",tourtype_Id);              
            rs=clbStm.executeQuery();            
            while(rs.next()){                            
                obj.setTourtype_Id(rs.getInt("tourtype_Id"));
                obj.setName(rs.getString("name"));
                obj.setDescription(rs.getString("description"));
            }            
            clbStm.close();
            rs.close();
            releaseConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tour_types.class.getName()).log(Level.SEVERE, null, ex);
            
        }finally{
              return obj;
          }
      }
        
    public ArrayList getListPackagetoursType(String orderBy, String ASCorDESC, String WhereClause, int PagingIndex, int PagingSize){
        try {
            ArrayList PackagetoursTypeList=new ArrayList();
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tour_types_getpaged(?,?,?,?,?)}");
            clbStm.setString("OrderBy", orderBy);
            clbStm.setString("TangGiam", ASCorDESC);
            clbStm.setString("WhereClause", WhereClause);
            clbStm.setInt("PageIndex", PagingIndex);
            clbStm.setInt("PageSize", PagingSize);
            rs=clbStm.executeQuery();
            DALTotalPageIndex.getTotalPage("tbl_Package_tour_types", WhereClause, PagingSize);
            while(rs.next()){
                Etbl_Package_tour_types obj=new Etbl_Package_tour_types();
                obj.setTourtype_Id(rs.getInt("tourtype_Id"));
                obj.setName(rs.getString("name"));
                obj.setDescription(rs.getString("description"));
                PackagetoursTypeList.add(obj);
            }
            clbStm.close();
            rs.close();
            releaseConnection();
            return PackagetoursTypeList;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tour_types.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }    
}
